import { Vue, Component, Watch } from 'vue-property-decorator'
import Login from "../components/login/login"
import ChatRoom from "../components/chatRoom/chatRoom"

@Component({
    template: require('./app.html'),
    components: { Login, ChatRoom }
})

export default class App extends Vue {
    currentView = "Login";
    nickName = "";

    mounted() {
        this.$socket.on("connect", (msg: any) => {
            console.log('socket connect')
            this.$socket.on("loginResult", (msg: any) => {
                console.log(msg)
            });
        });
        window.onbeforeunload = () => {
            this.$socket.emit('onbeforeunload', {
                name: this.nickName
            })
        };
        window.onunload = () => {
            this.$socket.emit('logout', {
                name: this.nickName
            })
        };
    }

    changeView(val: any) {
        this.currentView = val.viewName;
        this.nickName = val.nickName;
    }

}
